﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
using System.Net;
using KetBanBonPhuong;

namespace Tom
{
    /// <summary>
    /// Summary description for Utils
    /// </summary>
    public class Utils
    {
        public Utils()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        
        /// <summary>
        /// SendEmail
        /// </summary>
        /// <param name="email"></param>
        private static void SendEmail(MailMessage email)
        {
            try
            {
                email.From = new MailAddress("Ketban@ketbanbonphuong.com", "Kết bạn bốn phương");
                email.IsBodyHtml = true;
                SmtpClient client = new SmtpClient();
                client.UseDefaultCredentials = false;
                //client.Credentials = new NetworkCredential("vieclamonlinedotcom@gmail.com", "vieclam123");
                client.Credentials = new NetworkCredential("ngvlong.hut@gmail.com", "01051990");
                client.EnableSsl = true;
                client.Host = "smtp.gmail.com";
                client.Port = 587;
                client.Send(email);
            }
            catch (Exception)
            {

            }
        }

        /// <summary>
        /// SendEmail
        /// </summary>
        /// <param name="Address"></param>
        /// <param name="Subject"></param>
        /// <param name="Body"></param>
        private static void SendEmail(string Address, string Subject, string Content)
        {
            MailMessage newEmail = new MailMessage();
            newEmail.To.Add(Address);
            newEmail.Subject = Subject;
            newEmail.Body = Content;
            SendEmail(newEmail);
        }

        /// <summary>
        /// Send link to active account
        /// </summary>
        /// <param name="Email"></param>
        public static void SendActivelink(String Email, String WebsiteAddress)
        {
            String Content = "Chào mừng bạn đến với Ketbanbonphuong<br />. Hãy click vào địa chỉ sau để kích hoạt tài khoản:" + WebsiteAddress + "/Active.aspx?Email=" + Email;
            SendEmail(Email, "Chào mừng gia nhập Ketbanbonphuong", Content);
        }

        public static void SendPassword(String Email, String Password)
        {
            String Content = "Mật khẩu mới của bạn là: " + Password;
            SendEmail(Email, "Thông báo mật khẩu", Content);
        }

        // Check Friend
        public static bool CheckIsFriend(int UserID1, int UserID2)
        {
            bool isFriend = false;
            int FriendListID = FriendList.GetFrienListID(UserID1);
            if (FriendListID != -1)
            {
                int FriendID = Friend.GetFriendID(FriendListID, UserID2);
                if (FriendID != -1)
                {
                    if (Friend.GetInfo(FriendID).Is_subscriber)
                    {
                        isFriend = true;
                    }
                }
            }
            return isFriend;
        }
    }
}